<?php
	
	if (!defined('EXPONENT')) exit('');

	$cat = null;
	$id = 0;
	if(isset($_REQUEST['id']))
	{
		$id = intval($_REQUEST['id']); 
		$cat = $db->selectObject('surveymodule_catergory',"id=".$id);
		$loc=unserialize($cat->location_data);
	}
	if (exponent_permissions_check(array('administrate','configure'),$loc)) {

		$cat = surveymodule_cat::cat_survey_update($_POST,$cat);
		$cat->location_data = serialize($loc);
		
		$cat->rank = $db->max('surveymodule_catergory', 'rank', 'location_data', "location_data='".serialize($loc)."'");
		if ($cat->rank == null) {
			$cat->rank = 0;
		} else {
			$cat->rank += 1;
		}
		if (isset($cat->id)) {
			$db->updateObject($cat,'surveymodule_catergory');
		} else {
			$db->insertObject($cat,'surveymodule_catergory');
		}

		exponent_flow_redirect();
	} else {
		echo SITE_404_HTML;
	}

?>